package com.cxcy.swustlearner.service.Impl;

import com.cxcy.swustlearner.mapper.TaskMapper;
import com.cxcy.swustlearner.mapper.TaskStatusMapper;
import com.cxcy.swustlearner.pojo.Task;
import com.cxcy.swustlearner.pojo.TaskStatus;
import com.cxcy.swustlearner.service.TaskStatusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Transactional
@Service
public class TaskStatusServiceImpl implements TaskStatusService {
    @Autowired
    private TaskMapper taskMapper;
    @Autowired
    private TaskStatusMapper taskStatusMapper;
    @Override
    public void updateTaskStatus(TaskStatus taskStatus) {
        taskStatusMapper.updateTaskStatus(taskStatus);
        Task task=taskMapper.selectTaskByTaskId(taskStatus.getTaskId());
        if (taskStatus.getCompletedStatus()==1){
            task.setCompleted(task.getCompleted()+1);
        }else if (taskStatus.getCompletedStatus()==-1){
            task.setCompleted(task.getCompleted()-1);
        }
        taskMapper.updateTask(task);
    }

    @Override
    public List<TaskStatus> getAllTaskStatus(String taskId,int status) {
        return taskStatusMapper.getTaskStatus(taskId,status);
    }
}
